/**
 * 机构查询面板
 */
Ext.namespace("Ext.ux.sysmeta");

Ext.ux.sysmeta.SysTableQueryPanel = Ext.extend(Ext.Panel, {

	layout: 'border',
	title: '表结构查询',
	
	formPanel: null,
    grid: null,
    
	// 组件事件初始化
	initComponent: function(){
		Ext.ux.sysmeta.SysTableQueryPanel.superclass.initComponent.call(this);
		
		// 表结构查询面板
		var tableSearchForm = new Ext.FormPanel({
			region: 'north',
			labelWidth: 70,	
			labelAlign: 'right',
			collapsible: true,
			frame: true,
			title: '条件查询',
			width: '80%',
			height: 90,
			items: [{
				layout:'form',
				items:[{
					layout:'column',
					items:[{
						columnWidth: 0.33,
						layout: 'form',
						items: [{
							xtype: 'textfield',
							fieldLabel: '表名',
							name: 'tableName',
							anchor: '85%'
						}]
					},{	
						columnWidth: 0.33,
						layout: 'form',
						items: [{
							xtype: 'textfield',
							fieldLabel: '表注释',
							name: 'tableChineseComments',
							anchor: '85%'
						}]
					},{
						columnWidth: 0.33,
						layout: 'form',
						items: [{
							xtype: 'textfield',
							fieldLabel: '所属用户',
							name:'owner',
							anchor: '85%'
						}]
					}]
				},{
					layout:'column',
					items:[{	
						columnWidth: 0.33,
						layout: 'form',
						items: [{
							
						}]
					},{
						columnWidth: 0.33,
						layout: 'form',
						items: [{
							
						}]
					},{
						columnWidth: 0.33,
						layout: 'hbox',
						defaults: {margins:'0 5 0 0'},
						items:[{
							xtype: 'button',
							text: '查询',
							width: 87,
							handler: this.loadData,
							scope: this
						},{
							xtype: 'button',
							text: '清空',
							width: 87,
							handler: this.clearTableSearchForm,
							scope: this
						}]
					}]
				}]
			}]
	    });
	    
		this.formPanel = tableSearchForm;
	    this.add(tableSearchForm);
	
		//机构表格
		var tableGrid = new Ext.ux.grid.SysTableGrid({
			url: 'sys-meta-table!list.action',
			title: '表结构定义列表',
			margins: '2 0 0 0',
			region: 'center'
		});
		
		tableGrid.on('addRecord', function(){
			this.addTable();
		});

	    // 执行查询操作前传入条件查询参数
		tableGrid.getStore().on('beforeload', function(){
			tableGrid.getStore().baseParams = {
				tableName: tableSearchForm.form.findField('tableName').getValue(),
				tableChineseComments: tableSearchForm.form.findField('tableChineseComments').getValue(),
				owner: tableSearchForm.form.findField('owner').getValue()
				
			};
		});
		
		this.grid = tableGrid;
	    this.add(tableGrid);
	},
	
	loadData:function(){
		this.grid.getStore().reload();
	},
	
	// 定义机构查询条件清空方法
	clearTableSearchForm: function(){
		this.formPanel.form.reset();
		this.formPanel.form.findField('tableName').focus();
		this.grid.store.reload();
	}
});